package com.zhuiyun.educations.api.course.controller;

import com.zhuiyun.educations.api.course.entity.Course;
import com.zhuiyun.educations.api.course.entity.DTO.CourseDTO;
import com.zhuiyun.educations.api.course.service.CourseService;
import com.zhuiyun.educations.api.uploadFile.entity.FileManage;
import com.zhuiyun.educations.api.uploadFile.service.FileManageService;
import com.zhuiyun.educations.common.errorCode.CommonException;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CourseController
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/6/19 14:39
 **/
@RestController
@CrossOrigin
@RequestMapping("/course")
public class CourseController {
    @Resource
    CourseService courseService;

    @Resource
    FileManageService fileManageService;

    /**
     * @Author 杨友朋
     * @Description TODO 根据id修改课程信息
     * @Date 2023/6/26 9:57
     * @Return CommonResult
     * @param course
     */
    @PostMapping("/updateCourseById")
    public CommonResult updateCourseById(MultipartFile imageFile,Course course) {
        return courseService.updateCourseById(imageFile, course);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 添加课程信息
     * @Date 2023/6/26 9:57
     * @Return CommonResult
     * @param course
     */
    @PostMapping("/insertCourse")
    public CommonResult insertCourse(MultipartFile imageFile, MultipartFile file, Course course ,String projectName) throws CommonException {
        FileManage fileManage = fileManageService.saveFileToSystem(file, projectName);
        System.out.println("++++++++++"+fileManage);
        course.setInformationId(fileManage.getId());
        return courseService.insertCourse(imageFile,file, course);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据id删除课程
     * @Date 2023/6/26 9:58
     * @Return CommonResult
     * @param id
     */
    @GetMapping("/deleteCourseById")
    public CommonResult deleteCourseById(Integer id) {
        return courseService.deleteCourseById(id);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量删除课程
     * @Date 2023/6/26 9:59
     * @Return CommonResult
     * @param ids
     */
    @PostMapping("/deleteByCourseIds")
    public CommonResult deleteByCourseIds(@RequestBody List<Integer> ids) {
        return courseService.deleteByCourseIds(ids);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据id修改课程状态
     * @Date 2023/6/26 9:59
     * @Return CommonResult
     * @param course
     */
    @PostMapping("/updateCourseStatusById")
    public CommonResult updateCourseStatusById(@RequestBody Course course) {
        return courseService.updateCourseStatusById(course);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量修改课程状态
     * @Date 2023/6/26 14:06
     * @Return CommonResult
     * @param ids,course
     */
    @PostMapping("/updateCourseByIds")
    public CommonResult updateCourseByIds(@RequestBody List<Integer> ids, Course course) {
        return courseService.updateCourseByIds(ids,course);
    }
}
